/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package testing;

import clasificador.genetico.PoliticaEmparejamientoIndependiente;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import utils.Weighted;

/**
 *
 * @author Simply
 */
public class EmparejamientoString extends PoliticaEmparejamientoIndependiente<ArrayList<Character>> {
    private class Iterador implements Iterator<Weighted<ArrayList<Character>>> {
        ArrayList<Weighted<ArrayList<Character>>> poblacion;
        int parejas = 0;
        Random r;
        public Iterador(ArrayList<Weighted<ArrayList<Character>>> poblacion) {
            this.poblacion = poblacion;
            this.r = new Random();
        }
        @Override
        public boolean hasNext() {
            return parejas != poblacion.size();
        }

        @Override
        public Weighted<ArrayList<Character>> next() {
            parejas++;
            return poblacion.get(r.nextInt(poblacion.size()));
        }

        @Override
        public void remove() {
            parejas++;
        }
    }

    @Override
    protected Iterator<Weighted<ArrayList<Character>>> selectorIndividual(ArrayList<Weighted<ArrayList<Character>>> poblacion) {
        return new Iterador(poblacion);
    }
}
